package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.exception.Assert;
import com.atguigu.common.result.R;
import com.atguigu.common.result.ResponseEnum;
import com.atguigu.common.util.RegexValidateUtils;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.pojo.vo.LoginVO;
import com.atguigu.srb.core.pojo.vo.RegisterVO;
import com.atguigu.srb.core.pojo.vo.UserInfoVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Helen
 * @since 2021-02-20
 */

@Api(tags = "会员管理")
@RestController
@RequestMapping("/admin/core/userInfo")
@Slf4j
//@CrossOrigin
public class AdminUserInfoController {

    @Resource
    private UserInfoService userInfoService;

    @ApiOperation("获取会员分页列表")
    @GetMapping("/list/{page}/{limit}") //page:第几页 limit:每页记录数
    public R listPage(
            @ApiParam(value = "当前页面", required = true)
            @PathVariable Long page,
            @ApiParam(value = "每页记录数", required = true)
            @PathVariable Long limit,
            @ApiParam(value = "查询对象", required = false) //当required = false 是可以不写的
                    UserInfoQuery userInfoQuery
    ) {
        //把当前页码 和分页传入 生成一个分页对象 利用MabatisPlus
        Page<UserInfo> pageParam = new Page<>(page, limit);

        //然后使用userInfoService 执行查询 参数使用分页查询 使用条件查询
        //返回值怎么说 IPage<UserInfo> page1 = userInfoService.page(); 默认返回IPage
        IPage<UserInfo> pageModel = userInfoService.listPage(pageParam, userInfoQuery);

        //最后将整个分页信息 传到前端
        return R.ok().data("pageModel", pageModel);


    }

    @ApiOperation("锁定和解锁") //增post 删delete 改put 查get
    @PutMapping("/lock/{id}/{status}")  // 修改是PutMapping 根据用户的id重置用户的状态
    public R lock(
            @ApiParam(value = "用户ID", required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "状态（0：锁定 1：正常）", required = true)
            @PathVariable("status") Integer status) {

        userInfoService.lock(id, status);
        return R.ok().message(status == 1 ? "解锁成功" : "锁定成功");

    }
}


